
var host = 'http://58.30.240.29/wxbVideos';
var host = 'http://localhost/svn/tianxiong/wxbAdmin';
angular.module('starter.services', [])
    .factory('getData', function($http,$location,Static) {

        var GetData = function(params,$scope) {
            this.items = [];
            this.busy = false;
            this.page  = 1;
            this.pagecount = 10;
            this.end = false;
            params = params || {};
            this.id = params.id || '';
            this.playlistids = params.playlistids || '';
            this.kwd = params.kwd || '';
            this.orderBy = params.orderby || '';
            this.scope = $scope;

        };

        GetData.prototype.nextPage = function() {

            if (this.busy || this.end) return;

            this.busy = true;
            var req = {
                "category":this.id,
                "playlistids":this.playlistids,
                "pagecount":this.pagecount,
                "pagenum":this.page,
                "kwd":this.kwd,
                "orderBy":this.orderBy
            }
            var url =  Static.host + '/?r=TVPlaylist/playlist&data='+JSON.stringify(req)+'';
            console.log(url);

            $http.get(url).success(function(data) {

                var items = data.rows;

                for (var i = 0; i < items.length; i++) {
                    this.items.push(items[i]);
                }
                if(items.length<this.pagecount)
                {
                    this.busy = true;
                    this.end = true;
                }
                else
                {


                    this.page++;
                    this.busy = false;
                }




            }.bind(this));
        };

        return GetData;
    })
  .factory('OpenId',function($http,$q){
        var deferred = $q.defer();
        $http.get('http://wx.wefi.com.cn/WxAPI/userinfoapi.php')
            .success(function (data, status, headers, config) {
                deferred.resolve(data);
            })
            .error(function(data, status, headers, config){
                //deferred.resolve(data);

            })
        return deferred.promise;
    })
 .factory('SnToken',function($http,$q){
        var deferred = $q.defer();
        $http.get(host+'/?r=wx/getSnToken&openid=ohzhQt-SY1q1XWmgc39K36k9Dmfs')
            .success(function (data, status, headers, config) {
                deferred.resolve(data);
            })
            .error(function(data, status, headers, config){
                //deferred.resolve(data);
                deferred.reject('http error');
            })
        return deferred.promise;
 })
.factory('Nav',function($http,$q){
        var deferred = $q.defer();
        $http.get(host+'/?r=wxPages/getNav')
            .success(function (data, status, headers, config) {
                deferred.resolve(data);
            })
            .error(function(data, status, headers, config){
                //deferred.resolve(data);
                deferred.reject('http error');
            })
     return deferred.promise;
}).factory('Static',function($location){


   return {
       host:host
   }
 })